<?php

namespace App\Http\Middleware;

use Closure;
use App\Cart;
use Auth;

class CartExistCheck
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $user = Auth::user();
        //获取商品id
        $gid = $request->id;
        $cart = Cart::where('uid',$user->uid)->where('gid',$gid)->first();
        if(empty($cart)){
            return '该商品已删除';
        }
        return $next($request);
    }
}
